package com.learncloud.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.learncloud.common.core.wrapper.ResponseWrap;
import com.learncloud.common.core.wrapper.ResponseWrapUtil;
import com.learncloud.entity.VideoDramasSeries;
import com.learncloud.service.IVideoDramasSeriesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 视频集数表 前端控制器
 * </p>
 *
 * @author yj
 */
@RestController
@RequestMapping("/video/dramas-series")
public class VideoDramasSeriesController {

    @Autowired
    private IVideoDramasSeriesService iVideoDramasSeriesService;

    @PostMapping("add")
    @ApiOperation(value = "新增视频集数")
    public ResponseWrap add(@RequestBody VideoDramasSeries videoDramasSeries){
        iVideoDramasSeriesService.save(videoDramasSeries);
        return ResponseWrapUtil.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "修改视频集数")
    public ResponseWrap update(@RequestBody VideoDramasSeries videoDramasSeries){
        iVideoDramasSeriesService.updateById(videoDramasSeries);
        return ResponseWrapUtil.success();
    }

    @GetMapping("/getPaginationList")
    @ApiOperation(value = "查询视频集数分页列表")
    public ResponseWrap<Page> getPaginationList(Integer pageSize, Integer pageIndex, VideoDramasSeries videoDramasSeries){
        Page page = iVideoDramasSeriesService.page(new Page(pageIndex, pageSize),new QueryWrapper<>(videoDramasSeries).orderByAsc("sort"));
        return ResponseWrapUtil.success(page);
    }

    @GetMapping("/del")
    @ApiOperation(value = "删除视频")
    public ResponseWrap<Page> del(Integer id){
        iVideoDramasSeriesService.removeById(id);
        return ResponseWrapUtil.success();
    }

    @GetMapping("release")
    @ApiOperation(value = "发布,取消发布视频集数")
    public ResponseWrap release(Integer id){
        iVideoDramasSeriesService.release(id);
        return ResponseWrapUtil.success();
    }

}

